import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../views/Home.vue'
import Welcome from '../components/Welcome.vue'
import Users from '../components/user/Users.vue'
import Power from '../components/rights/Power.vue'
import Role from '../components/rights/Role.vue'
import Cate from '../components/goods/Cate.vue'
import Params from '../components/goods/Params.vue'
import List from '../components/goods/List.vue'
import Add from '../components/goods/Add.vue'
import Orders from '../components/orders/Orders.vue'
import Report from '../components/report/Report.vue'
import Type from '../components/pets/Type.vue'
import List1 from '../components/pets/LIst.vue'
import Add1 from '../components/pets/Add.vue'
import List2 from '../components/medics/List.vue'
import Record from '../components/medics/Record.vue'
import List3 from '../components/stock/List.vue'
import Intro from '../components/stock/introcude.vue'
Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: Login},
  { path: "/home",component:Home,
    redirect:'/welcome',
    children:[{path:'/welcome',component:Welcome},
              {path:'/users',component:Users},
              {path:'/rights',component:Power},
              {path:'/roles',component:Role},
              {path:'/categories',component:Cate},
              {path:'/params',component:Params},
              {path:'/goods',component:List},
              {path:'/goods/add',component:Add},
              {path:'/orders',component:Orders},
              {path:'/reports',component:Report},
              {path:'/pets',component:List1},
              {path:'/pets/add',component:Add1},
              {path:'/type',component:Type},
              {path:'/medics',component:List2},
              {path:'/records',component:Record},
              {path:'/stock',component:List3},
              {path:'/intro',component:Intro},
            ]}
]

const router = new VueRouter(
  { routes: routes })
  router.beforeEach((to,from,next)=>{
    if(to.path=="/login"){
     return next();
    }
    const token=window.sessionStorage.getItem("token")
    if(!token){
      return next('/login')
    }
    next()
  })

export default router
